package com.example.dllo.keepdemo.me;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.toolbox.ImageLoader;
import com.example.dllo.keepdemo.R;
import com.example.dllo.keepdemo.base.BaseFragment;
import com.example.dllo.keepdemo.main.MainActivity;
import com.example.dllo.keepdemo.tools.RoundImageView;
import com.example.dllo.keepdemo.tools.VolleySingleton;

/**
 * Created by dllo on 16/1/8.
 */
public class MeFragment extends BaseFragment {
    private Toolbar toolbar;
    private TextView tvName;
    private RoundImageView headImage;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_me, container, false);
        toolbar = (Toolbar) view.findViewById(R.id.toolbar_fragment_me);
        tvName = (TextView) view.findViewById(R.id.tv_fragment_me_title);
        headImage = (RoundImageView) view.findViewById(R.id.roundimg_fragment_me);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        Bundle bundle = getArguments();
        if (bundle != null) {
            tvName.setText(bundle.getString("username"));
            ImageLoader.ImageListener listener = ImageLoader.getImageListener(headImage,R.mipmap.person_45_45,R.mipmap.person_45_45);
            VolleySingleton.getImageLoader().get(bundle.getString("usericon"),listener);
        }


        toolbar.setTitle("");
        ((MainActivity) getActivity()).setSupportActionBar(toolbar);
        toolbar.setNavigationIcon(R.mipmap.jiahaoyou);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getActivity(), "添加好友", Toast.LENGTH_SHORT).show();
            }
        });

        setHasOptionsMenu(true);
    }

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        super.onCreateOptionsMenu(menu, inflater);
        getActivity().getMenuInflater().inflate(R.menu.menu_fragment_me, menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.menu_option_fragment_me:
                Toast.makeText(getActivity(), "设置", Toast.LENGTH_SHORT).show();
                break;
        }
        return true;
    }
}
